//
//  DiscoverDeviceView.m
//  iiecg
//
//  Created by 123456 on 2017/11/17.
//  Copyright © 2017年 Boundary Technology. All rights reserved.
//

#import "DiscoverDeviceView.h"
#import "UIView+Corner.h"

@interface DiscoverDeviceView ()

@property (nonatomic,strong)UILabel *cardLab;

@end

@implementation DiscoverDeviceView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setUpUI];
    }
    return self;
}

-(void)setDeviceID:(NSString *)deviceID
{
    _deviceID = deviceID;
    [IKPublicUtil runOnMainThread:^{
        self.cardLab.text = [INTERNATIONAL(@"string_device_id") stringByAppendingString:deviceID];
    }];
}

-(void)setUpUI
{
    self.backgroundColor = ECG_COLOR_WHITE;
    
    UIImageView *imageView = [[UIImageView alloc] init];
    imageView.image = [UIImage imageNamed:@"ecg_device_blind"];
    [self addSubview:imageView];
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(self.mas_top).with.offset(30);
        make.width.mas_equalTo(90);
        make.height.mas_equalTo(199);
    }];
    
    UILabel *lab = [[UILabel alloc] init];
    lab.text = INTERNATIONAL(@"string_found_device");
    lab.textAlignment = NSTextAlignmentCenter;
    lab.textColor = COLOR_BLACK_6F6F6F;
    lab.font = FONT_BASIC;
    [self addSubview:lab];
    [lab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(imageView.mas_bottom).with.offset(20);
        make.left.mas_equalTo(50);
        make.right.mas_equalTo(-50);
        make.height.mas_equalTo(40);
    }];
    
    self.cardLab = [[UILabel alloc] init];
    self.cardLab.textColor = [UIColor lightGrayColor];
    self.cardLab.textAlignment = NSTextAlignmentCenter;
    self.cardLab.font = FONT_LABEL;
    [self addSubview:self.cardLab];
    [self.cardLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
        make.top.equalTo(lab.mas_bottom).with.offset(15);
        make.height.mas_equalTo(30);
    }];
    
    UIButton *blindingButton = [[UIButton alloc] init];
    [blindingButton setTitle:INTERNATIONAL(@"string_bonded_device") forState:UIControlStateNormal];
    [blindingButton setTitleColor:ECG_COLOR_WHITE forState:UIControlStateNormal];
    [blindingButton addTarget:self action:@selector(blinding) forControlEvents:UIControlEventTouchUpInside];
    blindingButton.titleLabel.font = FONT_BUTTON;
    blindingButton.backgroundColor = COLOR_PALETTE_LIGHT_GREEN;
    blindingButton.cornerRadius = 25;
    [self addSubview:blindingButton];
    [blindingButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(30);
        make.right.mas_equalTo(-30);
        make.top.equalTo(self.cardLab.mas_bottom).with.offset(10);
        make.height.mas_equalTo(50);
    }];
    
    UIButton *goNext = [[UIButton alloc] init];
    NSString *str1 = [NSString stringWithFormat:@"%@ > ", INTERNATIONAL(@"string_rescan")];
    [goNext setTitle:str1 forState:UIControlStateNormal];
    [goNext.titleLabel setFont:FONT_BASIC];
    [goNext setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [goNext addTarget:self action:@selector(go) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:goNext];
    [goNext mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(blindingButton.mas_bottom).with.offset(5);
        make.centerX.equalTo(self) ;
        make.width.mas_equalTo(96);
        make.height.mas_equalTo(30);
    }];
}

-(void)blinding
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(callbackdonext)])
    {
        [self.delegate callbackdonext];
    }
}

-(void)go
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(callbackBack)])
    {
        [self.delegate callbackBack];
    }
}

@end

